<template>
  <DataList 
  :cate="cate" 
  :cols="cols"
  :name="name"
  :excelHeader="excelHeader"
  :groupCheck = "groupCheck" 
 ref="datalist"
  skipExcelNumber="5" />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import {get开设专业} from  "@/api/开设专业"
import { addShpx, deleteShpx, updateShpx, getShpx,bulkAddShpx } from "@/api/应届毕业生获证及社会培训情况.js";
import {findComponent} from "@/utils/ui";
import linq from "linq"
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A7-3-2应届毕业生获证及社会技术培训情况表",
      name: "7.3.2 应届毕业生获证及社会培训情况",
      excelHeader:{B3:"专业所属系部代码",C3:"专业所属系部名称",D3:"专业代码",E3:"专业名称（全称）",F3:"专业方向代码",G3:"专业方向名称（全称）",H3:"毕业生总数（人）",I3:"应届毕业生在校期间获取的符合专业面向职业资格证书情况",I4:"获得证书的毕业生",I5:"初级",K5:"中级",M5:"高级",O5:"无等级",I6:"人数",J6:"比例",K6:"人数",L6:"比例",M6:"人数",N6:"比例",O6:"人数",P6:"比例",Q3:"与专业相关的社会技术培训总数（人天）"},
      
      cols: [
        { label: "专业所属系部代码", prop: "BMBH" },
        { label: "专业所属系部名称", prop: "BMMC" },
        { label: "专业代码", prop: "ZYDM" },
        { label: "专业名称(全称)", prop: "ZYMC" },
        { label: "专业方向代码", prop: "ZYFXDM" },
        { label: "专业方向名称(全称)", prop: "ZYFXMC" },
        { label: "毕业生总数(人)", prop: "BYSS" },
        { label: "应届毕业生在校期间获取的符合专业面向职业资格证书情况" ,data:[
            {label:"获取证书的毕业生",data:[
              {label:"初级",data:[
                {label:"人数(人)",prop:"HCJZSRS"},
                {label:"比率(%)",prop:"HCJZSRSBL"}
                ]},
                {label:"中级",data:[
                {label:"人数(人)",prop:"HZJZSRS"},
                {label:"比率(%)",prop:"HZJZSRSBL"}
                ]},
                {label:"高级",data:[
                {label:"人数(人)",prop:"HGJYSZSRS"},
                {label:"比率(%)",prop:"HGJZSRSBL"}
                ]},
                {label:"无等级",data:[
                {label:"人数(人)",prop:"HWDJZSRS"},
                {label:"比率(%)",prop:"HWDJZSRSBL"}
                ]}
              ]}
        ]},
        { label: "与专业相关的社会技术培训总数(人天)", prop: "YZYXGDSHJSPXZS" },
      ],
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]="系部数:"+linq.from(list).distinct("$.BMBH").count()
         sums[8]="专业数:"+linq.from(list).distinct("$.ZYDM").count()
         sums[10]="方向数:"+linq.from(list).distinct("$.ZYFXDM").count()
         sums[12]="总人数:"+linq.from(list).sum("$.BYSS")
         sums[13]=""+linq.from(list).sum("$.HCJZSRS")
         sums[14]=""+((linq.from(list).sum("$.HCJZSRS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[15]=""+linq.from(list).sum("$.HZJZSRS")
         sums[16]=""+((linq.from(list).sum("$.HZJZSRS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[17]=""+linq.from(list).sum("$.HGJYSZSRS")
         sums[18]=""+((linq.from(list).sum("$.HGJYSZSRS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[19]=""+linq.from(list).sum("$.HWDJZSRS")
         sums[20]=""+((linq.from(list).sum("$.HWDJZSRS")/linq.from(list).sum("$.BYSS"))*100).toFixed(2)
         sums[21]=""+linq.from(list).sum("$.YZYXGDSHJSPXZS")
         sums[22]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
         sums[22]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
         sums[22] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
 
       return sums;
      //
    },
     async  onDlgCreated(model) {
            var dd = findComponent(this,"ZYFXMC");
          var ZYFXMC = linq.from( this.$root.开设专业).distinct("$.ZYFXMC").toArray();
        
          dd.$attrs.items = ZYFXMC.map(item => {
            return { label: item.ZYFXMC, value: item.ZYFXMC};
          });
    },

    async  bulkAdd(array){
       await  bulkAddShpx({Shpx:array});
    },
    onChange(model, field, value) {
      //
      if (field == "ZYFXMC") {
        
        var temp =  linq.from( this.$root.开设专业).first(item=>item.ZYFXMC==value);
        model.BMBH = temp.BMBH;
        model.BMMC = temp.BMMC;
        model.ZYMC = temp.ZYMC;
        model.ZYDM = temp.ZYDM;
        
        model.ZYFXDM = temp.ZYFXDM;
        
      }
      //
      model.HCJZSRSBL = ((Number(model.HCJZSRS)/Number(model.BYSS))*100).toFixed(2)+''
      model.HZJZSRSBL = ((Number(model.HZJZSRS)/Number(model.BYSS))*100).toFixed(2)+''
      model.HGJZSRSBL = ((Number(model.HGJYSZSRS)/Number(model.BYSS))*100).toFixed(2)+''
      model.HWDJZSRSBL = ((Number(model.HWDJZSRS)/Number(model.BYSS))/100).toFixed(2)+''
    },
    calField(list){
      list.forEach(model=>{
        model.HCJZSRSBL = ((Number(model.HCJZSRS)/Number(model.BYSS))*100).toFixed(2)+''

      model.HZJZSRSBL = ((Number(model.HZJZSRS)/Number(model.BYSS))*100).toFixed(2)+''
      model.HGJZSRSBL = ((Number(model.HGJYSZSRS)/Number(model.BYSS))*100).toFixed(2)+''
      model.HWDJZSRSBL = ((Number(model.HWDJZSRS)/Number(model.BYSS))/100).toFixed(2)+''
       model.HCJZSRSBL=isNaN(model.HCJZSRSBL)?0:model.HCJZSRSBL;
        model.HZJZSRSBL=isNaN(model.HZJZSRSBL)?0:model.HZJZSRSBL;
         model.HGJZSRSBL=isNaN(model.HGJZSRSBL)?0:model.HGJZSRSBL;
          model.HWDJZSRSBL=isNaN(model.HWDJZSRSBL)?0:model.HWDJZSRSBL;
      })
     },
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 专业 = await get开设专业(user.XXID,user.CJPC)
          
        //是否已经存在相同
          
          var err =  linq.from(array).select("$.ZYDM+','+$.ZYFXDM").except(linq.from(专业).select("$.ZYDM+','+$.ZYFXDM").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYFXDM) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"开设专业表不存在对应的专业代码与专业方向代码组合合");
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").except(linq.from(专业).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYMC+','+e.ZYFXDM+','+e.ZYFXMC) !==-1).
          forEach(e=>{
            var d = linq.from(专业).firstOrDefault(item=>item.ZYDM == e.ZYDM && item.ZYFXDM == e.ZYFXDM);
            if(d){
              e.ZYMC = d.ZYMC;
              e.ZYFXMC = d.ZYFXMC;
              e.BMMC = d.BMMC;
              e.BMBH = d.BMBH;
            }
          });
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
    async fetchData() {
    
      var datas = await getShpx(this.$root.user.XXID,this.$root.user.CJPC);
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          var model = await addShpx(temp);
          resolve(model);
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateShpx(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         await deleteShpx(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>